package com.cloud.code.真题;

import java.util.*;

/**
 * 全排列
 */
public class Demo680 {

    public static void main(String[] args) {
        boolean b = rotateString("abcde", "cdeab");
        System.out.println(b);
    }

    public static boolean rotateString(String s, String goal) {
        if(s.length() != goal.length()){
            return false;
        }
        int length = s.length();
        char[] chars = s.toCharArray();
        Deque<Character> dueue = new LinkedList<>();

        for (int i = 0; i < length; i++) {
            dueue.add(chars[i]);
        }

        for (int i = 0; i < length; i++) {
            String s1 = dueue.toString().replaceAll("\\W+","");
            if(s1.equals(goal)){
                return true;
            }
            dueue.addFirst(dueue.removeLast());
        }

        return false;
    }

}
